

#include <iostream>
#include <vector>
using namespace std;

struct TreeNode 
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
 
struct ListNode 
{
    int val;
    ListNode *next;
    ListNode() : val(0), next(nullptr) {}
    ListNode(int x) : val(x), next(nullptr) {}
    ListNode(int x, ListNode *next) : val(x), next(next) {}
};
 
class Solution
{
    int sum = 0;
    vector<int> path;
    vector<vector<int>> res;
public:
    vector<vector<int>> pathSum(TreeNode* root, int targetSum)
    {
        _pathSum(root, targetSum);

        return res;
    }

    ListNode* reverseList1(ListNode* head)
    {
        ListNode dummy1, dummy2;
        dummy1.next = head;

        for (ListNode* cur = dummy1.next, *next = nullptr; cur; cur = next)
        {
            next = cur->next;
            cur->next = dummy2.next;
            dummy2.next = cur;
        }

        return dummy2.next;
    }

    ListNode* reverseList2(ListNode* head)
    {
        ListNode* cur = head, * prev = nullptr;

        for (ListNode* next = nullptr; cur; cur = next)
        {
            next = cur->next;
            cur->next = prev;
            prev = cur;
        }

        return prev;
    }

    ListNode* reverseList3(ListNode* head)
    {
        return _reverseList3(head);
    }

private:
    ListNode* _reverseList3(ListNode* head)
    {
        if (nullptr == head)
            return nullptr;
        if (nullptr == head->next)
            return head;

        ListNode* newhead = _reverseList3(head->next);
        head->next->next = head;
        head->next = nullptr;

        return newhead;
    }

    void _pathSum(TreeNode* root, int goal)
    {
        if (nullptr == root)
            return;

        sum += root->val;
        path.push_back(root->val);

        _pathSum(root->left, goal);
        _pathSum(root->right, goal);

        if (!root->left && !root->right && sum == goal)
            res.push_back(path);

        sum -= root->val;
        path.pop_back();
    }
};

int main()
{


	return 0;
}